;
(function() {
  'use strict';

  angular.module('controllers.faultLocation.pbossOm')
    .controller('diskResourceController', diskResourceController);

  function diskResourceController(resourceServer) {
    var diskEcharts1 = echarts.init(document.getElementById('disk1'));
    var diskEcharts2 = echarts.init(document.getElementById('disk2'));
    var diskEcharts3 = echarts.init(document.getElementById('disk3'));
    disk();
    function disk() {
      resourceServer.disks(function(res) {
        diskEcharts1.clear();
        diskEcharts2.clear();
        diskEcharts3.clear();
        var arr1 = res.data[1];
        var arr2 = res.data[2];
        var arr3 = res.data[3];
        diskEcharts1.setOption(Echarts(arr1.hostip));
        diskEcharts2.setOption(Echarts(arr2.hostip));
        diskEcharts3.setOption(Echarts(arr3.hostip));
        setInterval(function() {
          diskEcharts1.addData([
            [0, Math.round(Math.random() * 1000), false, false]
          ]);
          diskEcharts2.addData([
            [0, Math.round(Math.random() * 1000), false, false]
          ]);
          diskEcharts3.addData([
            [0, Math.round(Math.random() * 1000), false, false]
          ]);
        }, 2000);
      });
    }

    function Echarts(textName) {
      var option = {};
      option.title = {
        text: textName
      };
      option.tooltip = {
        trigger: 'axis'
      };
      option.calculable = true;
      option.xAxis = [{
        type: 'category',
        boundaryGap: true,
        data: (function() {
          var res = [];
          var len = 60;
          while (len--) {
            res.push('');
          }
          return res;
        })()
      }];
      option.yAxis = [{
        type: 'value',
        name: '千字节/秒',
        scale: true,
        boundaryGap: [0.2, 0.2]
      }];
      option.series = [{
        type: 'line',
        data: (function() {
          var res = [];
          var len = 60;
          while (len--) {
            res.push(0);
          }
          return res;
        })(),
        smooth:true,
       itemStyle: {normal: {areaStyle: {type: 'default'}}}
      }];
      return option;
    }
  }
  diskResourceController.$inject = ['resourceServer'];
}());